import { Component, Vue, Inject } from 'vue-property-decorator';

import { IRoomBasicProperty } from '@/shared/model/room-basic-property.model';
import RoomBasicPropertyService from './room-basic-property.service';
import AlertService from '@/shared/alert/alert.service';

@Component
export default class RoomBasicPropertyDetails extends Vue {
  @Inject('roomBasicPropertyService') private roomBasicPropertyService: () => RoomBasicPropertyService;
  @Inject('alertService') private alertService: () => AlertService;

  public roomBasicProperty: IRoomBasicProperty = {};

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (to.params.roomBasicPropertyId) {
        vm.retrieveRoomBasicProperty(to.params.roomBasicPropertyId);
      }
    });
  }

  public retrieveRoomBasicProperty(roomBasicPropertyId) {
    this.roomBasicPropertyService()
      .find(roomBasicPropertyId)
      .then(res => {
        this.roomBasicProperty = res;
      })
      .catch(error => {
        this.alertService().showHttpError(this, error.response);
      });
  }

  public previousState() {
    this.$router.go(-1);
  }
}
